<template>
  <div class="allbackground">
    <center>
      <div style="display: flex; align-items: center">
        <div class="pageTurning pageTurningPre" @click="turnPagePre">
          <svg-icon
            icon-name="arrow"
            style="width: 40px; height: 40px"
          ></svg-icon>
        </div>
        <div class="background">
          <center>
            <div class="banner">
              <h1 class="bannertop">
                {{ noticeData.title }}
              </h1>
              <div class="bannerbottom">
                <div class="bannerbottomleft">
                  <div class="time">{{ noticeData.time }}</div>
                </div>
              </div>
            </div>
          </center>
          <div style="height: 2px; background-color: #c5c8c9"></div>
          <div class="content" v-html="noticeData.content"></div>
          <div class="bottomback" @click="$router.push('/employmentPolicy')">返回</div>
        </div>
        <div class="pageTurning pageTurningNext" @click="turnPageNext">
          <svg-icon
            class="flipArrow"
            icon-name="arrow"
            style="width: 40px; height: 40px"
          ></svg-icon>
        </div>
      </div>
    </center>
    <!-- <div class="back" @click="$router.push('/')">
            <svg-icon icon-class="detailback" class="backdetail"></svg-icon>
            <svg-icon icon-class="detailbackmove" class="movebackdetail"></svg-icon>
        </div> -->
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, watch } from "vue";
import { getNoticeDetail } from "@/api/employmentGuidance";
import { useRoute, useRouter } from "vue-router";
import { ElMessage } from "element-plus";

const route = useRoute();
const router = useRouter();

const noticeId = ref(route.query.id); // 定义一个响应式引用，初始值为当前 route.query.id

// 监控 route.query.id 的变化
watch(
  () => route.query.id, // 监控的源
  (newValue, oldValue) => {
    console.log(`query.id changed from ${oldValue} to ${newValue}`);
    noticeId.value = newValue; // 更新 queryId 的值
    queryNoticeDetail();
  }
);

const noticeData = ref({
  title: "",
  time: "",
  content: "",
  nextId: 0,
  prevId: 0,
});

const queryNoticeDetail = async () => {
  const res = await getNoticeDetail(noticeId.value);

  noticeData.value = res.data;
  console.log(noticeData.value);
};
queryNoticeDetail();

//跳转前一页
const turnPagePre = () => {
  if (noticeData.value.prevId === 0) {
    ElMessage.warning("已处于第一页");
  } else {
    router.push({
      path: "/Guidance/guidanceDetail",
      query: { id: noticeData.value.prevId },
    });
  }
};

//跳转后一页
const turnPageNext = () => {
  if (noticeData.value.nextId === 0) {
    ElMessage.warning("已处于最后一页");
  } else {
    router.push({
      path: "/Guidance/guidanceDetail",
      query: { id: noticeData.value.nextId },
    });
  }
};
</script>

<style lang="scss" scoped>
.allbackground {
  background-color: #efefef;
  padding: 50px 0;
  min-height: 100vh;
}

.background {
  width: 66.4%;
  margin: auto;
  background: #fff;
  padding: 5%;
}

.bannertop {
  font-size: 40px;
}

.banner {
  margin-bottom: 25px;
  position: relative;
}

.bannerbottom {
  display: flex;
  justify-content: space-between;
  margin-top: 25px;
}

.bannerbottomleft {
  width: 27%;
  display: flex;
  justify-content: space-between;
  font-size: 20px;
}

.bannerbottomright {
  display: flex;
  justify-content: space-between;
  font-size: 20px;
}

.time {
  display: flex;
  border: 1px solid #ccc;
  border-radius: 50px;
  padding: 20px 30px;
  justify-content: center;
  align-items: center;
}

.content {
  font-size: 20px;
  margin-top: 25px;
}

.mediaone,
.mediatwo,
.mediathree {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 70px;
  height: 70px;
  vertical-align: middle;
  border: 1px solid #ccc;
  border-radius: 100%;
  margin-left: 10px;
  margin-top: 10px;
  cursor: pointer;
}

.weibo {
  position: absolute;
  top: -133px;
  right: 12px;
  display: none;
  border: 1px solid #eee;
  z-index: 9;
  width: 200px;
  height: 192px;
  color: #666;
  font-size: 12px;
  text-align: center;
  box-shadow: 0 2px 10px #aaa;
  background-color: #fff;
}

.triangle {
  position: absolute;
  top: 60px;
  right: 101px;
  display: none;
  width: 0px;
  height: 0px;
  border: 15px solid transparent;
  border-top-color: #d7d7d7;
}

.mediatwo:hover .weibo {
  display: inline-block;
}

.mediatwo:hover .triangle {
  display: inline-block;
}

.top {
  font-weight: normal;
  height: 26px;
  line-height: 26px;
  font-size: 12px;
  background-color: #f3f3f3;
  margin: 0;
  padding: 0;
  color: #777;
}

.center {
  width: 105px;
  margin: 10px auto;
}

.back {
  padding: 10px;
  border: 1px solid lightgrey;
  border-radius: 50px;
  width: 50px;
  height: 50px;
  position: fixed;
  left: 1%;
  top: 275px;
  z-index: 1111;
  background-color: #fff;
  justify-content: space-around;
  cursor: pointer;
}

.back:hover {
  background-color: #5698c3;
}

.backdetail {
  position: absolute;
  top: 25px;
  left: 24px;
}

.movebackdetail {
  display: none;
  position: absolute;
  top: 25px;
  left: 24px;
}

.back:hover .movebackdetail {
  display: inline-block;
}

.back:hover .backdetail {
  display: none;
}

.bottomback {
  margin: 50px;
  padding: 15px;
  border: 1px solid lightgrey;
  border-radius: 50px;
  width: 125px;
  height: 26px;
  background-color: #fff;
  justify-content: space-around;
  cursor: pointer;
}

.bottomback:hover {
  background-color: #5698c3;
  color: #fff;
}

.pageTurning {
  width: 100px;
  height: 100px;
  background-color: #fff;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease; /* 添加过渡效果 */
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* 初始阴影效果 */
}

.pageTurningNext:hover {
  transform: translateY(-5px) translateX(5px); /* 鼠标移动时向上浮动 */
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); /* 鼠标移动时增强阴影效果 */
}
.pageTurningPre:hover {
  transform: translateY(-5px) translateX(-5px); /* 鼠标移动时向上浮动 */
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); /* 鼠标移动时增强阴影效果 */
}

.flipArrow {
  transform: rotate(180deg); /* 立即旋转 180 度，不使用过渡动画 */
}

:deep(img) {
  width: 80%;
}
</style>